package cn.javaxc.mvcwork.util.common;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.util.Date;



public class StringUtils {
	
	public static String allowed = "-0123456789.";
	private static Random rn = new Random();
	
	
	
	public static int getIntegerNumber(String in) {
		return Integer.parseInt(getNumber(in));
	}
	
	
	
	public static double getDoubleNumber(String in) {
		return Double.parseDouble(getNumber(in));
	}
	

	
	
	
	public static String toString(String s) {
		if (s != null) {
			return (s);
		} else {
			return ("");
		}
	}
	
	
	
	public static String toHtml(String s) {
		if (s != null) {
			if (s.trim().equals("")) {
				return ("&nbsp;");
			} else {
				return toHtmlValue(s);
			}
		} else {
			return ("&nbsp;");
		}
	}
	
	
	
	public static String toHtmlValue(String s) {
		if (s != null) {
			String htmlReady = s.trim();
//			htmlReady = htmlReady.replace( "&", "&amp;");
			htmlReady = htmlReady.replace( "\"", "&quot;");
			htmlReady = htmlReady.replace( "<", "&lt;");
			htmlReady = htmlReady.replace( ">", "&gt;");
			htmlReady = htmlReady.replace( "\r\n", "<br>");
			htmlReady = htmlReady.replace( "\n\r", "<br>");
			htmlReady = htmlReady.replace( "\n", "<br>");
			htmlReady = htmlReady.replace( "\r", "<br>");
			htmlReady = htmlReady.replace( "//lt;", "<");
			htmlReady = htmlReady.replace( "//gt;", ">");
			
			//a second call to the function (done in surveys)
			//changes <br> to &lt;br&gt;, this needs to be reverted
			htmlReady = htmlReady.replace( "&lt;br&gt;", "<br>");
			
			htmlReady = toHtmlChars(htmlReady);
			return (htmlReady);
		} else {
			return ("");
		}
	}
	
	
	
	public static String toHtmlChars(String htmlReady) {
		if (htmlReady != null) {
			htmlReady = htmlReady.replace( "\u00A1", "&iexcl;");
			htmlReady = htmlReady.replace( "\u00A2", "&cent;");
			htmlReady = htmlReady.replace( "\u00A3", "&pound;");
			htmlReady = htmlReady.replace( "\u00A4", "&curren;");
			htmlReady = htmlReady.replace( "\u00A5", "&yen;");
			htmlReady = htmlReady.replace( "\u00A6", "&brvbar;");
			htmlReady = htmlReady.replace( "\u00A7", "&sect;");
			htmlReady = htmlReady.replace( "\u00A8", "&uml;");
			htmlReady = htmlReady.replace( "\u00A9", "&copy;");
			htmlReady = htmlReady.replace( "\u00AA", "&ordf;");
			htmlReady = htmlReady.replace( "\u00AB", "&laquo;");
			htmlReady = htmlReady.replace( "\u00AC", "&not;");
			htmlReady = htmlReady.replace( "\u00AD", "&shy;");
			htmlReady = htmlReady.replace( "\u00AE", "&reg;");
			htmlReady = htmlReady.replace( "\u00AF", "&macr;");
			htmlReady = htmlReady.replace( "\u00B0", "&deg;");
			htmlReady = htmlReady.replace( "\u00B1", "&plusmn;");
			htmlReady = htmlReady.replace( "\u00B2", "&sup2;");
			htmlReady = htmlReady.replace( "\u00B3", "&sup3;");
			htmlReady = htmlReady.replace( "\u00B4", "&acute;");
			htmlReady = htmlReady.replace( "\u00B5", "&micro;");
			htmlReady = htmlReady.replace( "\u00B6", "&para;");
			htmlReady = htmlReady.replace( "\u00B7", "&middot;");
			htmlReady = htmlReady.replace( "\u00B8", "&cedil;");
			htmlReady = htmlReady.replace( "\u00B9", "&sup1;");
			htmlReady = htmlReady.replace( "\u00BA", "&ordm;");
			htmlReady = htmlReady.replace( "\u00BB", "&raquo;");
			htmlReady = htmlReady.replace( "\u00BC", "&frac14;");
			htmlReady = htmlReady.replace( "\u00BD", "&frac12;");
			htmlReady = htmlReady.replace( "\u00BE", "&frac34;");
			htmlReady = htmlReady.replace( "\u00BF", "&iquest;");
			htmlReady = htmlReady.replace( "\u00C0", "&Agrave;");
			htmlReady = htmlReady.replace( "\u00C1", "&Aacute;");
			htmlReady = htmlReady.replace( "\u00C2", "&Acirc;");
			htmlReady = htmlReady.replace( "\u00C3", "&Atilde;");
			htmlReady = htmlReady.replace( "\u00C4", "&Auml;");
			htmlReady = htmlReady.replace( "\u00C5", "&Aring;");
			htmlReady = htmlReady.replace( "\u00C6", "&AElig;");
			htmlReady = htmlReady.replace( "\u00C7", "&Ccedil;");
			htmlReady = htmlReady.replace( "\u00C8", "&Egrave;");
			htmlReady = htmlReady.replace( "\u00C9", "&Eacute;");
			htmlReady = htmlReady.replace( "\u00CA", "&Ecirc;");
			htmlReady = htmlReady.replace( "\u00CB", "&Euml;");
			htmlReady = htmlReady.replace( "\u00CC", "&Igrave;");
			htmlReady = htmlReady.replace( "\u00CD", "&Iacute;");
			htmlReady = htmlReady.replace( "\u00CE", "&Icirc;");
			htmlReady = htmlReady.replace( "\u00CF", "&Iuml;");
			htmlReady = htmlReady.replace( "\u00D0", "&ETH;");
			htmlReady = htmlReady.replace( "\u00D1", "&Ntilde;");
			htmlReady = htmlReady.replace( "\u00D2", "&Ograve;");
			htmlReady = htmlReady.replace( "\u00D3", "&Oacute;");
			htmlReady = htmlReady.replace( "\u00D4", "&Ocirc;");
			htmlReady = htmlReady.replace( "\u00D5", "&Otilde;");
			htmlReady = htmlReady.replace( "\u00D6", "&Ouml;");
			htmlReady = htmlReady.replace( "\u00D7", "&times;");
			htmlReady = htmlReady.replace( "\u00D8", "&Oslash;");
			htmlReady = htmlReady.replace( "\u00D9", "&Ugrave;");
			htmlReady = htmlReady.replace( "\u00DA", "&Uacute;");
			htmlReady = htmlReady.replace( "\u00DB", "&Ucirc;");
			htmlReady = htmlReady.replace( "\u00DC", "&Uuml;");
			htmlReady = htmlReady.replace( "\u00DD", "&Yacute;");
			htmlReady = htmlReady.replace( "\u00DE", "&THORN;");
			htmlReady = htmlReady.replace( "\u00DF", "&szlig;");
			htmlReady = htmlReady.replace( "\u00E0", "&agrave;");
			htmlReady = htmlReady.replace( "\u00E1", "&aacute;");
			htmlReady = htmlReady.replace( "\u00E2", "&acirc;");
			htmlReady = htmlReady.replace( "\u00E3", "&atilde;");
			htmlReady = htmlReady.replace( "\u00E4", "&auml;");
			htmlReady = htmlReady.replace( "\u00E5", "&aring;");
			htmlReady = htmlReady.replace( "\u00E6", "&aelig;");
			htmlReady = htmlReady.replace( "\u00E7", "&ccedil;");
			htmlReady = htmlReady.replace( "\u00E8", "&egrave;");
			htmlReady = htmlReady.replace( "\u00E9", "&eacute;");
			htmlReady = htmlReady.replace( "\u00EA", "&ecirc;");
			htmlReady = htmlReady.replace( "\u00EB", "&euml;");
			htmlReady = htmlReady.replace( "\u00EC", "&igrave;");
			htmlReady = htmlReady.replace( "\u00ED", "&iacute;");
			htmlReady = htmlReady.replace( "\u00EE", "&icirc;");
			htmlReady = htmlReady.replace( "\u00EF", "&iuml;");
			htmlReady = htmlReady.replace( "\u00F0", "&eth;");
			htmlReady = htmlReady.replace( "\u00F1", "&ntilde;");
			htmlReady = htmlReady.replace( "\u00F2", "&ograve;");
			htmlReady = htmlReady.replace( "\u00F3", "&oacute;");
			htmlReady = htmlReady.replace( "\u00F4", "&ocirc;");
			htmlReady = htmlReady.replace( "\u00F5", "&otilde;");
			htmlReady = htmlReady.replace( "\u00F6", "&ouml;");
			htmlReady = htmlReady.replace( "\u00F7", "&divide;");
			htmlReady = htmlReady.replace( "\u00F8", "&oslash;");
			htmlReady = htmlReady.replace( "\u00F9", "&ugrave;");
			htmlReady = htmlReady.replace( "\u00FA", "&uacute;");
			htmlReady = htmlReady.replace( "\u00FB", "&ucirc;");
			htmlReady = htmlReady.replace( "\u00FC", "&uuml;");
			htmlReady = htmlReady.replace( "\u00FD", "&yacute;");
			htmlReady = htmlReady.replace( "\u00FE", "&thorn;");
			htmlReady = htmlReady.replace( "\u00FF", "&yuml;");
			htmlReady = htmlReady.replace( "\u20AC", "&euro;");
			return (htmlReady);
		} else {
			return ("");
		}
	}
	
	
	
	public static String toPseudoHtmlValue(String s) {
		String htmlReady = toHtmlValue(s);
		htmlReady = htmlReady.replace( "<br>", "\r\n");
		return htmlReady;
	}
	
	
	
	public static String fromHtmlValue(String s) {
		if (s != null) {
			String htmlReady = s.trim();
			htmlReady = htmlReady.replace( "&quot;", "\"");
			htmlReady = htmlReady.replace( "&lt;", "<");
			htmlReady = htmlReady.replace( "&gt;", ">");
			htmlReady = htmlReady.replace( "&nbsp;", " ");
			htmlReady = htmlReady.replace( "<br>", "\r\n");
			htmlReady = htmlReady.replace( "<br />", "\r\n");
			return (htmlReady);
		} else {
			return ("");
		}
	}
	
	
	
	public static String toHtmlText(String s) {
		s = s.replace( "<br>\r\n", "<br>");
		s = s.replace( "\r\n", "<br>");
		return s;
	}
	
	
	
	public static String toHtmlTextValue(String s) {
		s = s.replace( "<br>\r\n", "\r\n");
		s = s.replace( "<br />\r\n", "\r\n");
		s = s.replace( "<br>", "\r\n");
		s = s.replace( "<br />", "\r\n");
		return s;
	}
	
	
	
	public static String toHtmlTextBlank(String s) {
		String htmlReady = s.replace( "<br>", "");
		return htmlReady;
	}
	
	
	
	public static String toDateTimeString(java.sql.Timestamp inDate) {
		try {
			return java.text.DateFormat.getDateTimeInstance(
					java.text.DateFormat.SHORT, java.text.DateFormat.LONG).format(
							inDate);
		} catch (NullPointerException e) {
		}
		return "";
	}
	
	
	
	public static String toDateTimeString(java.util.Date inDate) {
		try {
			return java.text.DateFormat.getDateTimeInstance(
					java.text.DateFormat.SHORT, java.text.DateFormat.LONG).format(
							inDate);
		} catch (NullPointerException e) {
		}
		return "";
	}
	
	
	
	public static String toDateString(java.sql.Timestamp inDate) {
		try {
			return java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT).format(
					inDate);
		} catch (NullPointerException e) {
		}
		return "";
	}
	
	
	
	public static String toDateString(java.sql.Date inDate) {
		try {
			return java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT).format(
					inDate);
		} catch (NullPointerException e) {
		}
		return "";
	}
	
	
	
	public static String toLongDateString(java.util.Date inDate) {
		try {
			return java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG).format(
					inDate);
		} catch (NullPointerException e) {
		}
		return "";
	}
	
	
	
	public static String toFullDateString(java.util.Date inDate) {
		try {
			return java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL).format(
					inDate);
		} catch (NullPointerException e) {
		}
		return "";
	}
	
	
	
	public static String sqlReplace(String s) {
		//s = s.replace( "<br>", "\r");
		
		String newString = "";
		char[] input = s.toCharArray();
		int arraySize = input.length;
		for (int i = 0; i < arraySize; i++) {
			if (input[i] == '\'') {
				newString += "\\\'";
			} else if (input[i] == '\\') {
				newString += "\\\\";
			} else {
				newString += input[i];
			}
		}
		return newString;
	}
	
	

	
	
	private static String getNumber(String in) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < in.length(); i++) {
			if (allowed.indexOf(in.charAt(i)) > -1) {
				sb.append(in.charAt(i));
			}
		}
		return sb.toString();
	}
	
	
	
	public static String getNumbersOnly(String in) {
		String allowed = "0123456789";
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < in.length(); i++) {
			if (allowed.indexOf(in.charAt(i)) > -1) {
				sb.append(in.charAt(i));
			}
		}
		return sb.toString();
	}
	
	
	
	public static String loadText(File file) throws java.io.IOException {
		String ls = System.getProperty("line.separator");
		StringBuffer text = new StringBuffer();
		BufferedReader in = new BufferedReader(new FileReader(file));
		String line = null;
		boolean hasLine = false;
		while ((line = in.readLine()) != null) {
			if (hasLine) {
				text.append(ls);
			}
			text.append(line);
			hasLine = true;
		}
		in.close();
		return text.toString();
	}
	
	
	
	public static String loadText(String filename) throws java.io.IOException {
		String ls = System.getProperty("line.separator");
		StringBuffer text = new StringBuffer();
		BufferedReader in = new BufferedReader(new FileReader(filename));
		String line = null;
		boolean hasLine = false;
		while ((line = in.readLine()) != null) {
			if (hasLine) {
				text.append(ls);
			}
			text.append(line);
			hasLine = true;
		}
		in.close();
		return text.toString();
	}
	
	
	
	public static void loadText(String filename, ArrayList lines, boolean ignoreComments) throws java.io.IOException {
		BufferedReader in = new BufferedReader(new FileReader(filename));
		String line = null;
		while ((line = in.readLine()) != null) {
			if (!ignoreComments || (ignoreComments && !line.startsWith("#") && !"".equals(
					line.trim()))) {
				lines.add(line);
			}
		}
		in.close();
	}
	
	
	
	public static void saveText(String filename, String data) throws java.io.IOException {
		BufferedWriter out = new BufferedWriter(new FileWriter(filename));
		out.write(data);
		out.close();
	}
	
	
	
	public static String addS(long count) {
		if (count == 1) {
			return "";
		} else {
			return "s";
		}
	}
	
	
	
	public static String addES(long count) {
		if (count == 1) {
			return "";
		} else {
			return "es";
		}
	}
	
	
	
	public static int parseInt(Object s,int _def){
		int i=_def;
		try{
			i=Integer.parseInt(""+s);
		}catch(Exception e){
		}
		return i;
	}
	
	
	
	public static double parseDouble(String tmp, double defaultValue) {
		try {
			return Double.parseDouble(tmp);
		} catch (Exception e) {
			return defaultValue;
		}
	}
	

	
	
	
	public static ArrayList toArrayList(String str, String tokenizer) {
		ArrayList convertedList = null;
		StringTokenizer tokens = new StringTokenizer(str, tokenizer);
		while (tokens.hasMoreTokens()) {
			if (convertedList == null) {
				convertedList = new ArrayList();
			}
			convertedList.add(tokens.nextToken());
		}
		return convertedList;
	}
		
	public static String randomString(int lo, int hi) {
		int n = rand(lo, hi);
		byte b[] = new byte[n];
		for (int i = 0; i < n; i++) {
			b[i] = (byte) rand('a', 'z');
		}
		return new String(b);
	}
	
	
	
	public static int rand(int lo, int hi) {
		int n = hi - lo + 1;
		int i = rn.nextInt() % n;
		if (i < 0) {
			i = -i;
		}
		return lo + i;
	}
	
	
	
	public static String jsEscape(String s) {
		if (s != null) {
			String jsReady = s.trim();
			jsReady = jsReady.replace( "%", "%25");
			jsReady = jsReady.replace( "\r\n", "%0A");
			jsReady = jsReady.replace( "\r", "%0A");
			jsReady = jsReady.replace( "\n", "%0A");
			jsReady = jsReady.replace( "\"", "%22");
			jsReady = jsReady.replace( "\\", "%5C");
			jsReady = jsReady.replace( "!", "%21");
			jsReady = jsReady.replace( "@", "%40");
			jsReady = jsReady.replace( "#", "%23");
			jsReady = jsReady.replace( "$", "%24");
			jsReady = jsReady.replace( "^", "%5E");
			jsReady = jsReady.replace( "&", "%26");
			jsReady = jsReady.replace( "'", "%27");
			jsReady = jsReady.replace( "(", "%28");
			jsReady = jsReady.replace( ")", "%29");
			jsReady = jsReady.replace( "=", "%3D");
			jsReady = jsReady.replace( " ", "%20");
			jsReady = jsReady.replace( "|", "%7C");
			jsReady = jsReady.replace( ",", "%2C");
			jsReady = jsReady.replace( ":", "%3A");
			jsReady = jsReady.replace( ";", "%3B");
			jsReady = jsReady.replace( "<", "%3C");
			jsReady = jsReady.replace( ">", "%3E");
			jsReady = jsReady.replace( "?", "%3F");
			jsReady = jsReady.replace( "[", "%5B");
			jsReady = jsReady.replace( "]", "%5D");
			jsReady = jsReady.replace( "{", "%7B");
			jsReady = jsReady.replace( "}", "%7D");
			jsReady = jsReady.replace( "`", "%60");
			jsReady = jsReady.replace( "~", "%7E");
			return (jsReady);
		} else {
			return ("");
		}
	}
	
	
	
	public static String jsStringEscape(String s) {
		if (s != null) {
			String jsReady = s.trim();
			jsReady = jsReady.replace( "\"", "\\\"");
			jsReady = jsReady.replace( "\\", "\\\\");
			jsReady = jsReady.replace( "\r", "\\r");
			jsReady = jsReady.replace( "\n", "\\n");
			jsReady = jsReady.replace( "\t", "\\t");
			jsReady = jsReady.replace( "'", "\\'");
			return (jsReady);
		} else {
			return ("");
		}
	}
	
	
	
	public static String trimToSize(String text, int size) {
		if (text != null && text.length() > size) {
			return (text.substring(0, (size - 1)) + "...");
		} else {
			return text;
		}
	}
	
	
	
	public static String trimToSizeNoDots(String text, int size) {
		if (text != null && text.length() > size) {
			return (text.substring(0, (size)));
		} else {
			return text;
		}
	}
	
	
	
	public static String parseToDbString(String str) {
		return parseToDbString(str, ",");
	}
	
	
	
	public static String parseToDbString(String str, String delimiters) {
		StringBuffer result = new StringBuffer("");
		StringTokenizer tokenizer = new StringTokenizer(str, delimiters);
		for (int i = 0; tokenizer.hasMoreTokens(); i++) {
			String token = tokenizer.nextToken();
			if (i > 0) {
				result.append(", ");
			}
			result.append("'" + token.trim() + "'");
		}
		return result.toString();
	}
	
	
	
	public static String getLineSeparated(ArrayList displayList) {
		return getSeparatedBy(displayList, "\r\n");
	}
	
	
	
	public static String getCommaSeparated(ArrayList displayList) {
		return getSeparatedBy(displayList, ",");
	}
	
	
	
	public static String getSeparatedBy(ArrayList displayList, String separator) {
		StringBuffer sb = new StringBuffer();
		try {
			Iterator j = displayList.iterator();
			while (j.hasNext()) {
				String display = (String) j.next();
				if (j.hasNext()) {
					sb.append(display + separator);
				} else {
					sb.append(display);
				}
			}
		} catch (Exception e) {
		}
		return sb.toString().trim();
	}
	
	
	
	public static String valueOf(boolean tmp) {
		if (tmp) {
			return "true";
		} else {
			return "false";
		}
	}
	
	public static String[] getFirstLastNames(String name) {
		String[] result = new String[2];
		String nameFirst = null;
		String nameLast = null;
		boolean lastFirstFormat = (name.indexOf(",") != -1);
		if (lastFirstFormat) {
			StringTokenizer str = new StringTokenizer(name, ",");
			nameLast = str.nextToken().trim();
			if (str.hasMoreTokens()) {
				nameFirst = str.nextToken().trim();
				if ("".equals(nameFirst.trim())) {
					nameFirst = null;
				}
			}
		} else {
			StringTokenizer str = new StringTokenizer(name);
			nameFirst = str.nextToken().trim();
			if (str.hasMoreTokens()) {
				nameLast = str.nextToken().trim();
			} else {
				nameLast = nameFirst;
				nameFirst = null;
			}
		}
		result[0] = nameFirst;
		result[1] = nameLast;
		return result;
	}
	
	
	public static boolean isTrue(String tmp) {
		if (tmp != null) {
			return "true".equals(tmp.trim());
		}
		return false;
	}
	
	
	public static boolean isNumeric(String string) {
		return string.matches("^[-+]?\\d+(\\.\\d+)?$");
	}
	
	
	
	public static String parseStringForNumber(String inputString, int precision, boolean precisionMandatory) {
		String precissionStr = "";
		try {
			if(isNumeric(inputString) && precisionMandatory){
				if(precision == 0){
					precissionStr= inputString.substring(0, inputString.indexOf("."));
				} else {
					if(inputString.substring(inputString.indexOf(".") + 1).equals("0")){
						precissionStr = inputString.substring(0, inputString.indexOf("."));
					} else {
						precissionStr = inputString.substring(inputString.indexOf(".") + 1, inputString.length());  	              
						if(precissionStr.length() < precision){  	              	 
							precissionStr = inputString.substring(0, inputString.indexOf(".") + precissionStr.length() + 1);
						} else {  	              	 
							precissionStr = inputString.substring(0, inputString.indexOf(".") + (precision + 1));
						}
					}
				}
			} else {
				return inputString;
			}
		} catch (Exception e){
			e.printStackTrace();
			return "error: number cannot be resolved";
		}
		return precissionStr;
	}
	
	
	public static boolean isNumeric(char c) {	  
		if ((c >= '0') && (c <= '9')) return true; // valid
		else return false; // invalid	  
	}
	public static boolean startsWith(String[] arr,String s){
		for (String _s:arr) {
			if (s.startsWith(_s)){
				 return true;
			}
		}
		return false;
	}
	public static boolean isNullData(Object obj){
		if(obj==null)return true;
		if (obj instanceof String){
			return ((String)obj).isEmpty()||"-1".equals(obj);
		}else if (obj instanceof Integer){
			return (Integer)obj==-1;
		}
		return false;
	}
	public static String createUUID() {
		String t1 = UUID.randomUUID().toString();
			return t1.replaceAll("-", "").toUpperCase();

	}
	public static String getSuffix(String str,String separator){
		int offset=str.lastIndexOf(separator);
		if(offset==-1)offset=0;else offset=offset+1;
		return str.substring(offset,str.length());
	}
	public static String getPrefix(String str,String separator){
		if(str==null)return "";
		String ret=null;
		int offset=str.lastIndexOf(separator);
		if(offset==-1)offset=str.length();else offset=offset;
		ret=str.substring(0,offset);
			
		return ret;
	}
	public static String trim(String str){
        if(str == null)
            return null;
        else
            return str.trim();
    }
  
  public static void saveTextFile(String text, String filename) throws java.io.IOException {
    File outputFile = new File(filename);
    FileWriter out = new FileWriter(outputFile);
    out.write(text);
    out.close();
  }
	



  
  public static String htmlToText(String html) {
    if (html.length() == 0) {
      return html;
    }
    //Some things that will make the text look similar to the Html
    html = html.replace( "&nbsp;", " ");
    html = html.replace( "<br>", "\r\n");
    html = html.replace( "<br />", "\r\n");
    //handle paragraphs
    html = html.replace( "<p>", "");
    html = html.replace( "</p>", "\r\n\r\n");
    //handle lists
    html = html.replace( "<ol>", "\r\n");
    html = html.replace( "<ul>", "\r\n");
    html = html.replace( "<li>", "* ");
    html = html.replace( "</li>", "\r\n");
    html = html.replace( "</ul>", "\r\n");
    html = html.replace( "</ol>", "\r\n");
    //Now strip the rest of the tags
    StringBuffer st = new StringBuffer();
    int max = html.length();
    boolean tag = false;
    for (int i = 0; i < max; i++) {
      char c = html.charAt(i);
      if (!tag && c == '<') {
        tag = true;
      }
      if (!tag) {
        st.append(c);
      }
      if (tag && c == '>') {
        tag = false;
      }
    }
    String finalHtml = st.toString();
    finalHtml = finalHtml.replace( "&lt;", "<");
    finalHtml = finalHtml.replace( "&gt;", ">");
    finalHtml = finalHtml.replace( "&amp;", "&");
    return finalHtml;
  }

  public static Object isEmpty(Object value,Object _def){
		if (isNullData(value)){
			return _def;
		}else{
			return value;
		}
	}
  public static String toSingleLine(String s) {
		return CommonUtil.toSingleLine(s);
	}
	public static String getHumpString(String s){
		String hump="";
		if (s==null){
			return hump;	
		}
		for (int i=0;i<s.length() ;i++ ){
			if (i==0){
				hump+=s.charAt(i);
			}else if (s.charAt(i)!='_'){
				if (s.charAt(i-1)=='_'){
					hump+=Character.toUpperCase(s.charAt(i));
				}else{
					hump+=s.charAt(i);
				}			
			}
		}
		return hump;
	}
}
